package br.com.document.job.session;

import java.util.Properties;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import br.com.document.manager.session.LPSession;
import br.com.document.manager.session.SessionConfig;

public class LPointSessionFactory {
	
	public static LPSession getLPointSession(SessionConfig config){
		final String usuario = config.getParameter("user");
		final String senha = config.getParameter("password");
		final String schema = config.getParameter("schema");
		//TODO: validar usuario e senha e realizar o lookup de acordo com sua permissao.
		
		try {
			  Properties props = new Properties();

			  props.setProperty("java.naming.factory.initial", 
			                    "com.sun.enterprise.naming.SerialInitContextFactory");

			  props.setProperty("java.naming.factory.url.pkgs", 
			                    "com.sun.enterprise.naming");

			  props.setProperty("java.naming.factory.state",
			                    "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");

			  // optional.  Defaults to localhost.  Only needed if web server is running 
			  // on a different host than the appserver    
			  props.setProperty("org.omg.CORBA.ORBInitialHost", "192.168.0.100");

			  // optional.  Defaults to 3700.  Only needed if target orb port is not 3700.
			  props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

			  InitialContext context = new InitialContext(props);
			  JobSession session = (JobSession) context.lookup("br.com.document.job.session.JobSession");
			  return session;
		} catch (NamingException e) {
			e.printStackTrace();
		}
		return null;
	}

}
